#include <bits/stdc++.h>
using namespace std;
int a[200100];
int fun(int l,int r){
    if(r-l==1) return 0;
    int maxn=0;
    if(a[l]==a[r]) maxn=a[l];
    if(r-l==2) return maxn;
    for(int i=l+1;i<=r-2;i++){
        maxn=max(maxn,fun(l,i)+fun(i+1,r));
    }
    return maxn;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    scanf("%d",&t);
    while(t>0){
        t--;
        int n,i;
        scanf("%d",&n);
        for(i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        cout<<fun(1,n)<<endl;
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
